package com.sc.base.admin.config;

import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class StartedEventListener implements ApplicationListener<ContextRefreshedEvent> {

    private static final Logger logger = LoggerFactory.getLogger(StartedEventListener.class);

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
         ConvertUtils.register(new DateConverter(null), Date.class);
         if(AppDataContext.getContext() == null){
             AppDataContext.setApplicationContext(event.getApplicationContext());
             logger.info("sc-base-admin-core OK");
         }
    }
}
